<template>
  <div v-if="mode === 'read'" class="read-text">
    <span class="text">{{ curBizObject[card.cardCode] }}</span>
  </div>
  <a-textarea
    v-else
    class="card-textarea"
    type="text"
    v-model:value="val"
    :showCount="true"
    :rows="rows.defaultValue"
    :placeholder="placeHolder.defaultValue"
  />
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue';

export default defineComponent({
  name: 'CardTextarea',
  props: {
    mode: {
      type: String,
      default: '',
    },
    card: {
      type: Object as any,
      default: () => ({}),
    },
    curBizObject: {
      type: Object as any,
      default: () => ({}),
    },
  },
  setup(props, context) {
    const ctlValue = computed(() => props.card.controls.ctlValue);
    const rows = computed(() => props.card.controls.rows);
    const placeHolder = computed(() => props.card.controls.placeHolder);
    const val = computed({
      get: () => ctlValue.value.value ?? ctlValue.value.defaultValue,
      set: (val) =>
        context.emit('updateValue', val, 'value', props.card.controls.ctlValue),
    });

    return {
      val,
      rows,
      placeHolder,
    };
  },
});
</script>

<style lang="less" scoped>
.card-textarea {
  width: 100%;
  font-size: 12px;
  line-height: 22px;
  border-radius: 4px;
}
.read-text {
  padding: 6px 12px;
  background-color: @rb-background-color;
  .text {
    display: inline-block;
    line-height: 22px;
  }
}
</style>
